package test.aat.dxfy.demo01;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

public class HelpJavaBeanMyBatisXml {
	private static String str = "";
	private static String splitStr = ",";
	private static String txt = "";

	public static void main(String[] args) throws IOException {
		str=readFromTxt("e:\\1.txt");
		txt=readFromTxt("e:\\2.txt");
		toHtml();
		
		//1 
		//toJavaFiled();
		
		//2   
		//toDbFiled();
		
		//3   
		//toAdd();
		
		//4   
		//toUpt();
		
		//5 
		//toQuery();
		
		
		
	}
	
	public static void toHtml(){
		String[] ss = str.split(splitStr);
		String[] tt = txt.split(splitStr);
		String str="";
		int i=0;
		for (String s : ss) {
			if (null != s) {
				str=str+"<div class=\"form-group \">\n";
				str=str+"    <label for=\""+s+"\" class=\"control-label col-lg-2\">"+tt[i]+"</label>\n";
				str=str+"    <div class=\"col-lg-6\">\n";
				str=str+"        <input class=\" form-control\" id=\""+s+"\" name=\""+s+"\"  value=\"${m."+s+"}\"  type=\"text\" required />\n";
				str=str+"    </div>\n</div>\n";
				i++;
			}
		}
		System.out.println(str+" \n");
	}
	
	public static String readFromTxt(String path){
		try{
			File f=new File(path);
			BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(
					f), "gbk"));
			String s = null;
			String str="";
			while((s=br.readLine())!=null){
				str=str+s+splitStr;
			}
			br.close();
			return str;
		}catch(Exception e){
			
		}
		
		return "";
	}
	
	public static String[] readName(String file, String encoding) {
		String[] name = null;
		String str = null;
		try {
			InputStreamReader in = new InputStreamReader(new FileInputStream(
					file), encoding);
			char[] ch = new char[1024 * 4];
			int n;
			while ((n = in.read(ch)) != -1) {
				in.read(ch, 0, n);
			}
			for (int i = 0; i < n; i++) {
				if (ch[i] == '\t' || ch[i] == '\n' || ch[i] == '\r') {
					continue;
				} else {
					str += ch[i];
				}
			}
			str = new String(ch);
			name = str.trim().split(",");
			in.close();
			return name;
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return name;
	}
	
	public static void toJavaFiled(){
		String[] ss = str.split(splitStr);
		String str="";
		for (String s : ss) {
			if (null != s) {
				str=str+"private String "+s+";\n";
			}
		}
		System.out.println(str);
	}
	
	public static void toDbFiled() {
		try {

			String[] ss = str.split(splitStr);
			int i = 0;
			String sql = "";
			for (String s : ss) {
				if (null != s) {
					s = s + ",";
				}
				sql += s;
				i++;
				if (i % 5 == 0) {
					sql += "\n";
				}
			}
			System.out.println(sql);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println();
	}

	public static void toAdd() {
		try {

			String[] ss = str.split(splitStr);
			int i = 0;
			String sql = "";
			for (String s : ss) {
				if (null != s) {
					s = "#{" + s + "},";
				}
				sql += s;
				i++;
				if (i % 5 == 0) {
					sql += "\n";
				}
			}
			System.out.println(sql);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println();
	}

	public static void toUpt() {
		try {

			String[] ss = str.split(splitStr);
			String sql = "";
			for (String s : ss) {
				if (null != s) {
					s = "<if test=\"" + s + " != null\">" + s + " = #{"
							+ s + "},</if>";
				}
				sql += s;
				sql += "\n";
			}
			System.out.println(sql);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void toQuery() {
		try {

			String[] ss = str.split(splitStr);
			String sql = "";
			for (String s : ss) {
				if (null != s) {
					s = "<if test=\"" + s + " != null\"> AND " + s + " = #{"
							+ s + "} </if>";
				}
				sql += s;
				sql += "\n";
			}
			System.out.println(sql);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
